<?php
namespace App\Http\Controllers\Admin;
// +----------------------------------------------------------------------
// | Copyright (c) 2024~至今 迪钰国际旅行社 版权所有.
// +----------------------------------------------------------------------
// | Author: dxf &lt;xiangfei2007@126.com&gt;
// +----------------------------------------------------------------------
// | Date: 2024/8/16 14:07
// +----------------------------------------------------------------------

use App\Exceptions\InternalException;
use App\Exceptions\TokenInvalidException;
use App\Http\Controllers\Controller;
use App\Http\Requests\Admin\AdminAuthRequest;
use App\Logics\AuthLogic;
use Illuminate\Http\Request;

class AuthController extends Controller{

    /**
     * 登录接口
     * @param AdminAuthRequest $request
     * @return bool|mixed|string
     * @throws InternalException
     * @throws TokenInvalidException
     * Date:    2024/8/16 17:55
     */
    public function login(AdminAuthRequest $request){
        $old_token = $request->header('token');
        $params = $request->all();
        $authLogic = new AuthLogic();
        $result = $authLogic->adminLogin($params,$old_token);
        return $this->success($result);
    }

    /**
     * 退出登录接口
     * @param Request $request
     * @return mixed
     * @throws InternalException
     * Date:    2024/8/20 15:10
     */
    public function logout(Request $request): mixed
    {
        $token = $request->header('token');
        $authLogic = new AuthLogic();
        $authLogic->adminLogout($token);
        return $this->message('退出成功');
    }
}
